// components/Menu/menu.js
var systemInfo = wx.getSystemInfoSync();
var behaviorsbasic = require('../../behavior/basic') 
Component({
  behaviors: [behaviorsbasic],
  /**
  * 组件的属性列表
  */
  properties: {
    memberinfo:{
      type: Object,
      default: ''
    },
    diypara: {
      type: Object,
      default: ''
    },
    objmodel: {
      type: Object,
      default: ''
    }, 

  },

  /**
  * 组件的初始数据
  */
  data: {
    datalist:[],
    // datalist: ['https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1819216937,2118754409&fm=26&gp=0.jpg',
    //   'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg',
    //   'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1603365312,3218205429&fm=26&gp=0.jpg',
    //   'https://dss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1730713693,2130926401&fm=26&gp=0.jpg',
    //   'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1819216937,2118754409&fm=26&gp=0.jpg',
    
     
    // ],

    isShow: false,//是否已经弹出
    animMain: {},//旋转动画
    animAdd: {},//item位移,透明度
    animDelLots: {},//item位移,透明度
    animatios: [],
    Animationbox:{},
  },

  ready() {

    var objmodel= this.data.objmodel

    this.setData({datalist:objmodel.main.datalist})


     if(objmodel.com=='normal'){
       this.popnormal()

     }



    // var animatios = [];
    // if (this.datalist) {
    //   datalist.forEach(item => {
    //     animatios.push({})
    //   })
    // }
    // this.setData(animatios)
  },
  /**
  * 组件的方法列表
  */
  methods: {



    itemclick:function(ev){
    

      var item =ev.currentTarget.dataset.item
   
      if(item.cid=="6"){
         if(item.url=="phone"){
           wx.makePhoneCall({
             phoneNumber: item.val,
             success:function(){

             },
             fail:function(){

             }
           })
         }
         else if(item.url=='share'){
           var widgetsshare = this.selectComponent("#qwidgetsshare");
           widgetsshare.showSharefunc({id:item.poster?item.poster.id:'',type:item.poster?item.poster.type:''})
         }


      }
      else
      {

        this.diynavigateTo(ev)
      }
     

    },
    //点击弹出或者收起
    showOrHide: function () {
      if (this.data.isShow) {
        //缩回动画
        this.takeback();
        this.setData({
          isShow: false
        })
      } else {
        //弹出动画
        this.popnormal();
        this.setData({
          isShow: true
        })
      }
    },
    add: function () {
      this.triggerEvent("addEvent")
      this.showOrHide()
    },
    deleteLots: function () {
      this.triggerEvent("deleteLotsEvent")
      this.showOrHide()
    },
    popnormal: function () {
      var  objmodel = this.data.objmodel

      var animatios = []
      var baisc =0
      var updatemdoel = {}
      var interval = -objmodel.main.basic.interval.val / 750 * systemInfo.windowWidth     
      if(objmodel.com!='normal')
      {
        baisc = -objmodel.main.basic.r.val/ 750 * systemInfo.windowWidth      
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      animationMain.rotateZ(360).step();
      updatemdoel["animMain"] = animationMain.export()
      }     
       var px=0,py=0
       var ilen=  this.data.datalist.length
      this.data.datalist.forEach((item, n) => {
        var Animation = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease-out'
        })
        switch(objmodel.com)
        {
          case "normal":{
          
          }
          case "shrink":{
            //垂直
            py=n * interval + baisc           
            break ;
          }
          case "horizontal":{
            //水平
            px=n * interval + baisc
            break ;
          }      
          case "circular":{

            var startangle = parseInt(objmodel.main.basic.startangle)
            var endangle = parseInt(objmodel.main.basic.endangle)
  
            var stepa = Math.PI * (endangle - startangle) / 180 / ilen
            var r =baisc
            var startpi = Math.PI * startangle / 180
            px = -r * Math.cos(startpi + stepa * (n))
  
            py = -r * Math.sin(startpi + stepa * (n))
           
            break ;
          } 
          
        }
        animatios[n] = Animation.translate(px,py).rotateZ(360).opacity(1).step().export();   
      
        
      })    
      updatemdoel['animatios'] = animatios;
      
    
      this.setData(updatemdoel)
    },
    popp: function () {

      var animatios = []
    
      var r = 100

      var Animation = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })

      var startpi=0
      var endstartpi=Math.PI *2
    var stepa=  (endstartpi -startpi)/this.data.datalist.length

    
      // p2(x + r*Math.cos(A), y + r*Math.sin(A))

          this.data.datalist.forEach((item, n) => {

        animatios[n] = Animation.translate(r*Math.cos(startpi+stepa*(n-1)), r*Math.sin(startpi+stepa*(n-1)) ).rotateZ(180).opacity(1).step().export();
      })



      // animatios[0] = Animation.translate(0, -100).rotateZ(180).opacity(1).step().export();
      // animatios[1] = Animation.translate(-60, -60).rotateZ(180).opacity(1).step().export();
      // animatios[2] = Animation.translate(-100, 0).rotateZ(180).opacity(1).step().export();
      // animatios[3] = Animation.translate(-60, 60).rotateZ(180).opacity(1).step().export();
      // this.data.datalist.forEach((item, n) => {

      //   animatios[n] = Animation.translate(0, (n) * interval + baisc).rotateZ(180).opacity(1).step().export();
      // })
      var updatemdoel = {}
      updatemdoel['animatios'] = animatios;
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      animationMain.rotateZ(180).step();
      updatemdoel["animMain"] = animationMain.export()
      this.setData(updatemdoel)
    },

    //弹出动画
    popp2: function () {

      var animatios = []
      var baisc = -200 / 750 * systemInfo.windowWidth
      var interval = -120 / 750 * systemInfo.windowWidth

 
      this.data.datalist.forEach((item, n) => {
        var Animation = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease-out'
        })
        animatios[n] = Animation.translate(0, (n) * interval + baisc).rotateZ(180).opacity(1).step().export();
      
      })
      var updatemdoel = {}
      updatemdoel['animatios'] = animatios;
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      animationMain.rotateZ(180).step();
      updatemdoel["animMain"] = animationMain.export()


      var Animationbox = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      updatemdoel["Animationbox"]=Animationbox.height(550).translate(0,-500).step().export()
      this.setData(updatemdoel)
    },




    //弹出动画
    takeback: function () {

      var animatios = []
      var Animation = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      }).translate(0, 0).rotateZ(0).opacity(0).step().export();
      this.data.datalist.forEach((item, n) => {

        animatios[n] = Animation
      })
      var updatemdoel = {}
      updatemdoel['animatios'] = animatios;
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      animationMain.rotateZ(0).step();
      updatemdoel["animMain"] = animationMain.export()


      var Animationbox = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      updatemdoel["Animationbox"]=Animationbox.height('100rpx').translate(0,0).step().export()
      this.setData(updatemdoel)
    },


  },
  //解决滚动穿透问题
  myCatchTouch: function () {
    return
  }
})